<div class="pageContent">
	<div class="panelBar" style="background-color:#f2f6f9">
		<ul class="toolBar">
			<li>指定日期：<input type="text" class="date" size="10" readonly="true" id="dsm_date_<?cs var:config.machine_id ?>" value="<?cs var:config.cust_date ?>" onblur="setTimeout(dsmOnCustDateChange_<?cs var:config.machine_id ?>, 600);" minDate="2014-01-01" maxDate="2088-12-31" /></li>
			<li><a class="add" href="#" onclick="return dsmAttrShow_<?cs var:config.machine_id ?>(2);"><i class='icon-bar-chart icon-large'></i>日图</a></li>
			<li class="line">line</li>
			<li><a class="add" href="#" onclick="return dsmAttrShow_<?cs var:config.machine_id ?>(1);"><i class='icon-area-chart icon-large'></i>日同比图</a></li>
			<li class="line">line</li>
			<li><a class="add" href="#" onclick="return dsmAttrShow_<?cs var:config.machine_id ?>(3);"><i class='icon-area-chart icon-large'></i>周图</a></li>
			<li class="line">line</li>
			<li style='line-height:34px'>
    			<input type="checkbox" checked id="dsm_not_show_zero_<?cs var:config.machine_id ?>" onclick="return dsmCheckShowZero_<?cs var:config.machine_id ?>();"/>
	    		<label class='for' for='dsm_not_show_zero_<?cs var:config.machine_id ?>'>图表不显示数据为0的点</label>
			</li>
			<li style="display:none"><a id="dsm_href_<?cs var:config.machine_id ?>" href="#" target="navTab" rel="showmachine_<?cs var:config.machine_id ?>" fresh="false"></a></li>
			<li class="line">line</li>
			<li style='float:right;margin-right:20px'><a class="add" href="#" onclick="return dsmLeftMenuShow_<?cs var:config.machine_id ?>();"><i class='icon-large' id='navi-show-icon_<?cs var:config.machine_id ?>'></i>图表导航菜单</a></li>
			&nbsp;&nbsp;&nbsp;<li><span id="dsm_show_proc_<?cs var:config.machine_id ?>"></span></li>
		</ul>
	</div>

	<div> 
		<div id='dsmLeftMenu_<?cs var:config.machine_id ?>' layoutH="28" class="chartLeftMenu chart_navi">
            <div class="accordion" style='display:none'> 
            	<div class="accordionHeader attr_use_global_plug">
            		<h2><i class="icon-plug icon-large "></i><span class='navi_chart_text'>全局插件</span><i class="icon icon-chevron-up"></i></h2>
            	</div>
            	<div class="accordionContent attr_use_global_plug navi_attr_type_sub">
            		<ul class="tree"></ul>
            	</div>
 
            	<div class="accordionHeader attr_use_cust">
            		<h2><i class="icon-screenshot icon-large "></i><span class='navi_chart_text'>自定义监控点</span><i class="icon icon-chevron-up"></i></h2>
            	</div>
            	<div class="accordionContent attr_use_cust navi_attr_type_sub">
            		<ul class="tree"></ul>
            	</div>
            </div>
		</div> 

		<div layoutH="28" class="unitBox xrk_chart_container" id="dsm_ct_attr_show_list_<?cs var:config.machine_id ?>"> 
		</div>
	</div>
</div>

<script language="javascript" type="text/javascript">

var dsm_attr_list_arry_<?cs var:config.machine_id ?> = new Array();
var dsm_attr_list_<?cs var:config.machine_id ?> = <?cs var:config.attr_list ?>;
var dsm_attr_show_index_cur_<?cs var:config.machine_id ?>;
var dsm_machine_name_<?cs var:config.machine_id ?> = '<?cs var:config.machine_name ?>';
var dsm_attr_show_get_auto_<?cs var:config.machine_id ?> = null;
var dsm_attr_show_get_last_seq_<?cs var:config.machine_id ?> = <?cs var:config.last_seq ?>;
var dsm_attr_show_type_<?cs var:config.machine_id ?> = <?cs var:config.show_type ?>;
var dsm_attr_show_reqstart_timestamp_<?cs var:config.machine_id ?> = 0;
var dsm_cust_date_save_<?cs var:config.machine_id ?> = '<?cs var:config.cust_date ?>';
var dsm_attr_show_process_<?cs var:config.machine_id ?> = false;

function dsmCheckShowZero_<?cs var:config.machine_id ?>()
{
    var ckName = "local_dsm_not_show_zero_<?cs var:config.machine_id ?>";
    var ck = $("#dsm_not_show_zero_<?cs var:config.machine_id ?>").is(":checked");
    if(ck)
        window.localStorage.setItem(ckName, '1');
    else
        window.localStorage.setItem(ckName, '0');
    return dsmAttrShow_<?cs var:config.machine_id ?>(dsm_attr_show_type_<?cs var:config.machine_id ?>);
}

function dsmAttrShow_<?cs var:config.machine_id ?>(type)
{
	var dt = $("#dsm_date_<?cs var:config.machine_id ?>").val();
	if(dt != "")
		param = '&date=' + dt;
	else
		param = "&date=today" 

    var ck = $("#dsm_not_show_zero_<?cs var:config.machine_id ?>").is(":checked");
    if(ck)
        param += '&show_zero=0';
    else 
        param += '&show_zero=1';

	param += '&_r=' + Math.random();
	param += '&machine_id=' + '<?cs var:config.machine_id ?>';
	param += '&type=' + type;

	var requrl = "<?cs var:config.cgipath ?>mt_slog_showview?action=show_machine_attr" + param;
	var idhref = "#dsm_href_<?cs var:config.machine_id ?>";
	if(type == 1)
		$(idhref).html('日同比图');
	else if(type== 2) 
		$(idhref).html('日图');
	else
		$(idhref).html('周图');

	$(idhref).attr('href', requrl);
	$(idhref).click();
	return false;
}

function dsmClickMachineAttr_<?cs var:config.machine_id ?>(show_id)
{
	var arrStr = show_id.split('_');
	var page_start_index = 0;
	for(var i=0; i < dsm_attr_list_arry_<?cs var:config.machine_id ?>.length; i++)
	{
		if(page_start_index+<?cs var:config.per_count ?> <= i)
			page_start_index += <?cs var:config.per_count ?>;

		if(arrStr[1] == dsm_attr_list_arry_<?cs var:config.machine_id ?>[i])
			break;
	}

	// 非法 attr
	if(i >= dsm_attr_list_arry_<?cs var:config.machine_id ?>.length)
		return false;

	// 已获取到的 attr, 没有数据上报
	if(page_start_index < dsm_attr_show_index_cur_<?cs var:config.machine_id ?>)
		return false;

	// 正在获取中的 attr
	return true;
}

function dsmAttrShowDate2_<?cs var:config.machine_id ?>(idx)
{
	var reqAttr = dsm_attr_list_arry_<?cs var:config.machine_id ?>.slice(
			idx, idx+<?cs var:config.per_count ?>);
	if(reqAttr.length <= 0)
	{
        if(dsm_attr_show_process_<?cs var:config.machine_id ?> || $('#my_background').css('display') != 'none') {
            setTimeout(function() { $("#my_background,#my_progressBar").hide(); }, 1000);
        }
		return;
	}

	var requrl = "<?cs var:config.cgipath?>mt_slog_showview";
	var reqpara = {};

    var ck = $("#dsm_not_show_zero_<?cs var:config.machine_id ?>").is(":checked");
    if(ck)
        reqpara.show_zero = 0;
    else 
		reqpara.show_zero = 1;

	reqpara.machine_id = <?cs var:config.machine_id ?>;
	reqpara.attr_list = reqAttr.toString();
	reqpara.action = 'show_machine_attr_cust';
	reqpara.last_seq = dsm_attr_show_get_last_seq_<?cs var:config.machine_id ?>;;
	reqpara.type = dsm_attr_show_type_<?cs var:config.machine_id ?>;
	if(dsm_attr_show_get_auto_<?cs var:config.machine_id ?> == 'auto')
		reqpara.global = false;
	else
		reqpara.global = true;

	var dt = $("#dsm_date_<?cs var:config.machine_id ?>").val();
	if(dt != "")
		reqpara.date = dt;
	else
		reqpara.date = 'today';
	reqpara._r = Math.random();
	dsm_attr_show_index_cur_<?cs var:config.machine_id ?> = idx; 

	// 首次获取上报耗时信息
	if(idx == 0)
	{
		var d = new Date();
		dsm_attr_show_reqstart_timestamp_<?cs var:config.machine_id ?> = d.getTime();
		reqpara.req_timestamp = dsm_attr_show_reqstart_timestamp_<?cs var:config.machine_id ?>;
	}

    if(!dsm_attr_show_process_<?cs var:config.machine_id ?>){
        if(new Date().getTime() > dsm_attr_show_reqstart_timestamp_<?cs var:config.machine_id ?>+300) {
            $('#my_progressBar font').text('图表加载中, 请稍等...');
            $("#my_background,#my_progressBar").show();
            dsm_attr_show_process_<?cs var:config.machine_id ?> = true;
        }
    }

    ajaxTodoPost(requrl, reqpara, function(json) {
            if(dmtFirstDealAjaxResponse(json))
			return;

		if(json.statusCode == DWZ.statusCode.success ||json.statusCode == DWZ.statusCode.ok)
		{
			if(dsm_attr_show_get_last_seq_<?cs var:config.machine_id ?> != json.last_req_seq)
				return;

			dmtShowAttrInfo(json.attr_list, json.attr_val_list, 
				'#dsm_ct_attr_show_list_<?cs var:config.machine_id ?>', 'machine');

			// ajax 自动获取
			if(dsm_attr_show_index_cur_<?cs var:config.machine_id ?> + <?cs var:config.per_count ?>
				< dsm_attr_list_arry_<?cs var:config.machine_id ?>.length) 
			{
				dsm_attr_show_get_auto_<?cs var:config.machine_id ?> = 'auto';
				dsmAttrShowDate2_<?cs var:config.machine_id ?>(
					dsm_attr_show_index_cur_<?cs var:config.machine_id ?> + <?cs var:config.per_count ?>);
			}
			else
            {
				dsm_attr_show_get_auto_<?cs var:config.machine_id ?> = null;
                if(dsm_attr_show_process_<?cs var:config.machine_id ?> || $('#my_background').css('display') != 'none') {
                    setTimeout(function() { $("#my_background,#my_progressBar").hide(); }, 1000);
                }
            }
		}
		else if(json.msgid && alertMsg)
		{
			var msg = DWZ.msg(json.msgid);
			alertMsg.info(msg);
		}
		else if(json.msg)
			alertMsg.info(json.msg);
	});
}

function dsmOnCustDateChange_<?cs var:config.machine_id ?>()
{
	var dt = $("#dsm_date_<?cs var:config.machine_id ?>").val();
	if(dt != dsm_cust_date_save_<?cs var:config.machine_id ?>)
	{
		return dsmAttrShow_<?cs var:config.machine_id ?>(dsm_attr_show_type_<?cs var:config.machine_id ?>);
	}
}

function dsmLeftMenuShow_<?cs var:config.machine_id ?>()
{
	if($('#dsmLeftMenu_<?cs var:config.machine_id ?>').css('display') == 'none')
	{
        $('#navi-show-icon_<?cs var:config.machine_id ?>').removeClass('icon-double-angle-left').addClass('icon-double-angle-right');;
		$('#dsmLeftMenu_<?cs var:config.machine_id ?>').show();
		window.localStorage.setItem('dsmLeftMenu_<?cs var:config.machine_id ?>_hide', '0');
		dmtRedrawCharts('<?cs var:config.machine_id ?>', 'machine', true);
	}
	else
	{
        $('#navi-show-icon_<?cs var:config.machine_id ?>').addClass('icon-double-angle-left').removeClass('icon-double-angle-right');;
		$('#dsmLeftMenu_<?cs var:config.machine_id ?>').hide();
		window.localStorage.setItem('dsmLeftMenu_<?cs var:config.machine_id ?>_hide', '1');
		dmtRedrawCharts('<?cs var:config.machine_id ?>', 'machine', false);
	}
}

function dsmSetNaviMenuInfo_<?cs var:config.machine_id ?>()
{
    var rurl = '<?cs var:config.cgipath?>mt_slog_attr?action=get_attr_type_for_chart';
    $.ajax({
        type: "get",
        url: rurl,
        success: function(js) {
            if(dmtFirstDealAjaxResponse(js))
                return;
            if(typeof js.ret == 'undefined' || js.ret != 0) {
                alertMsg.warn("监控点类型信息获取失败，图表导航功能暂不能使用");
                return;
            }
            $('#dsmLeftMenu_<?cs var:config.machine_id ?>').css('padding-bottom', '1px');
            var ary_attr_types = dmtGetAttrTypeList(dsm_attr_list_<?cs var:config.machine_id ?>);

            // 生成私有监控点类型信息
            dmtSetChartNavigatioInfo(
                ary_attr_types, js.user_self_cust, 'dsmLeftMenu_<?cs var:config.machine_id ?> .attr_use_cust');
       
            // 生成全局插件监控点类型信息
            dmtSetChartNavigatioInfo(
                ary_attr_types, js.global_plug, 'dsmLeftMenu_<?cs var:config.machine_id ?> .attr_use_global_plug');

            var listattr = dsm_attr_list_<?cs var:config.machine_id ?>.list;
            for(var j=0; j < dsm_attr_list_<?cs var:config.machine_id ?>.count && j < listattr.length; j++) 
            {
                var list = '';
                var attr_show_id = "attr_" + listattr[j].id + "_<?cs var:config.machine_id ?>machine";
                list += "<li>";
                list += "<a onclick=\"dmtJumpToAttrPic('";
                list += attr_show_id + "', '#dsm_ct_attr_show_list_<?cs var:config.machine_id ?>', ";
                list += dsmClickMachineAttr_<?cs var:config.machine_id ?> + ")\" href='#' ctid='" + attr_show_id + "'>";
                list += listattr[j].name;
                list += "</a>";
                list += "</li>";
                $('#dsmLeftMenu_<?cs var:config.machine_id ?> ul[attr_type="' + listattr[j].attr_type + '"').append(list);
            }
            $('#dsmLeftMenu_<?cs var:config.machine_id ?>').initUI();
            $('#dsmLeftMenu_<?cs var:config.machine_id ?> .accordion').show();
        },
        dataType: 'json', 
        global: false
    });
}


$(document).ready(function(){
    var notShowZero = window.localStorage.getItem("local_dsm_not_show_zero_<?cs var:config.machine_id ?>");
	if(notShowZero === '1')
		$("#dsm_not_show_zero_<?cs var:config.machine_id ?>").prop('checked', true);
	else if(notShowZero === '0')
		$("#dsm_not_show_zero_<?cs var:config.machine_id ?>").prop('checked', false);

	$('#dsm_ct_attr_show_list_<?cs var:config.machine_id ?>').html('');
    dmtGetAttrIdList(dsm_attr_list_<?cs var:config.machine_id ?>, dsm_attr_list_arry_<?cs var:config.machine_id ?>);
    var hideLeft = window.localStorage.getItem("dsmLeftMenu_<?cs var:config.machine_id ?>_hide");
    if(hideLeft === '1')  {
        $('#dsmLeftMenu_<?cs var:config.machine_id ?>').hide();
        $('#navi-show-icon_<?cs var:config.machine_id ?>').addClass('icon-double-angle-left');
    	dmtSetRedrawChartsInfo('<?cs var:config.machine_id ?>', 'machine', false);
    }
    else if(hideLeft === '0') {
        $('#navi-show-icon_<?cs var:config.machine_id ?>').addClass('icon-double-angle-right');
    	dmtSetRedrawChartsInfo('<?cs var:config.machine_id ?>', 'machine', true);
    }
    else {
        if(dsm_attr_list_arry_<?cs var:config.machine_id ?>.length <= 10) {
            $('#dsmLeftMenu_<?cs var:config.machine_id ?>').hide();
            $('#navi-show-icon_<?cs var:config.machine_id ?>').addClass('icon-double-angle-left');
    	    dmtSetRedrawChartsInfo('<?cs var:config.machine_id ?>', 'machine', false);
        }
        else {
            $('#navi-show-icon_<?cs var:config.machine_id ?>').addClass('icon-double-angle-right');
    	    dmtSetRedrawChartsInfo('<?cs var:config.machine_id ?>', 'machine', true);
        }
    }
	dmtSetChartSize();

    if(dsm_attr_list_arry_<?cs var:config.machine_id ?>.length > 0) {
	    dsmAttrShowDate2_<?cs var:config.machine_id ?>(0);
        dsmSetNaviMenuInfo_<?cs var:config.machine_id ?>();
    }
    else {
        dmtAddNoDataTextForView(
            'dsmLeftMenu_<?cs var:config.machine_id ?>', 'dsm_ct_attr_show_list_<?cs var:config.machine_id ?>');
    }
});

</script>

